package struts2.listener;

import java.util.Date;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.PreResultListener;

/**
 * @Description：在action调用完成之后，result调用之前，调用PreResultListener
 * @author：涂有
 * @date 2015年11月1日 下午9:18:46
 */
public class PreResultListenerAction extends ActionSupport{

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	private String name;
	private String password;
	
	public String execute(){
		
		ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
		invocation.addPreResultListener(new PreResultListener() {
			
			@Override
			public void beforeResult(ActionInvocation arg0, String arg1) {
				
				System.out.println("返回的视图名：" + arg1);
				arg0.getInvocationContext().put("date", new Date());
			}
		});
		
		return LOGIN;
	}
}
